package com.iot08.common.utils;

import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.*;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import lombok.extern.slf4j.Slf4j;

/**
 * @author weichao 1299101858@qq.com
 * @version 1.0
 * @date 2021-10-25 19:11
 */
@Slf4j
public class SampleUtil {


    private static com.aliyun.dysmsapi20170525.Client client;

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    private static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static com.aliyun.dysmsapi20170525.Client getSignleClient(){
        if(client != null){
            return client;
        }else{
            try {
                client = createClient("LTAI5tQagBVMiDQNRTWbPGUK", "FKhwH8H9zWY7QPPyy0e6kPV2384cPn");
            } catch (Exception e) {
                e.printStackTrace();
                log.error("创建 阿里短信SMS客户端失败:"+e.getMessage(), e);
            }
            return client;
        }
    }



}